package com.basic.codetool;

import com.basic.common.FuncStatic;

public class FieldInfo {
	private String fieldName = null;
	private String fieldType = null;
	private boolean isKey = false;
	/**
	 * 传入字段信息，用逗号分隔
	 * fieldName, fieldType,
	 * @param value
	 * @return
	 */
	public static FieldInfo instance(String value){
		FieldInfo info = new FieldInfo();
		String[] fields = value.split(",");
		info.fieldName = fields[0];
		info.fieldType = fields[1];
		return info;
	}
	public String getFieldName() {
		return fieldName;
	}
	public String getFieldNameHump() {
		return FuncStatic.convertUpperCaseToHump(fieldName.toUpperCase());
	}
	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}
	public String getFieldType() {
		return fieldType;
	}
	public void setFieldType(String fieldType) {
		this.fieldType = fieldType.toLowerCase();
	}
	public void setIsKey(){
		this.isKey = true;
	}
	public boolean getIfKey(){
		return this.isKey;
	}
	
	public String getFieldAnnot(){
		if(this.fieldType.indexOf("bigint") > -1){
			return "@FieldBigNumber";
		}
		if(this.fieldType.indexOf("int") > -1){
			return "@FieldNumber";
		}
		if(this.fieldType.indexOf("varchar") > -1){
			return "@FieldString";
		}
		if(this.fieldType.indexOf("time") > -1){
			return "@FieldDate";
		}
		if(this.fieldType.indexOf("text") > -1){
			return "@FieldClob";
		}
		if(this.fieldType.indexOf("char") > -1){
			return "@FieldChar";
		}
		return "";
	}
}
